package Text2;

import java.util.*;

public class Main {
    //把 1∼n这 n个整数排成一行后随机打乱顺序，输出所有可能的次序。
    public static final int N = 15;
    public static int n;
    public static boolean[] st = new boolean[N];// true表示用过，false表示还未用过
    public static int[] arr=new int[N];

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        n = scanner.nextInt();
        dfs(1);
    }

    private static void dfs(int u) {
        if (u > n) {
            for (int i = 1; i <=n ; i++) {
                System.out.print(arr[i]+" ");
            }
            System.out.println();
            return;
        }
        for (int i = 1; i <=n ; i++) {
            if(!st[i]){
                arr[u]=i;
                st[i]=true;
                dfs(u+1);
                arr[u]=0;
                st[i]=false;
            }
        }
    }
}
